import { createRouter, createWebHistory } from 'vue-router'
import report from '../components/student/qualityReport.vue'
import talent from '../components/boss/excellentTalent.vue'
import space from '../views/boss/SpaceView.vue'
const PersonInformation = () => import('../components/boss/bossSpace/personInformation.vue'); 
// const PersonInformationDisplay = () => import('../components/boss/bossSpace/personInformationDisplay.vue'); 
const PositionManagement = () => import('../components/boss/bossSpace/positionManagement.vue'); 
const ChangePassword = () => import('../components/boss/bossSpace/changePassword.vue'); 
const Inbox = () => import('../components/boss/bossSpace/Inbox.vue'); 
const Outbox = () => import('../components/boss/bossSpace/outbox.vue');
// ------------------认证中心
import certificateAuthority from '../views/student/certificateAuthority/certificateAuthorityView.vue'
const Competition = () => import('../components/student/certificateAuthority/Competition.vue'); 
const ProjectExperience = () => import('../components/student/certificateAuthority/ProjectExperience.vue'); 
const InternshipExperience = () => import('../components/student/certificateAuthority/InternshipExperience.vue'); 
const Activity = () => import('../components/student/certificateAuthority/Activity.vue'); 
const SpecialGroup = () => import('../components/student/certificateAuthority/SpecialGroup.vue');
const Skills = () => import('../components/student/certificateAuthority/Skills.vue');
const course =()=>import('../components/student/course.vue')
const courseMessage=()=>import('../components/student/courseMessage.vue')
// --------------------认证中心

// -------------教师端
import TeacherView from '@/views/teacher/teacherView.vue'
import workBench from '../components/teacher/workBench.vue';
import ProjectReview from '../components/teacher/projectReview.vue';
import CompetitionReview from '../components/teacher/competitionReview.vue';
import InternshipReview from '../components/teacher/InternshipReview.vue';
import SpecialStudentManagement from '../components/teacher/specialStudentManagement.vue';
import GraduateDestinationStatistics from '../components/teacher/graduateDestinationStatistics.vue';
import ActivityReview from '../components/teacher/activity.vue';
import SkillsReview from '../components/teacher/skillsReview.vue';
import SpecialReview from '@/components/teacher/specialReview.vue';
// ----------------教师端


import personalcenter from '../components/student/personalCenter.vue'
import assessment from '../components/student/assesssment-center.vue'
import assessmenttopic from '../components/student/assessmentTopic.vue'
import modifiedinformation from '../components/student/modifiedInformation.vue'
import updatePassword from '../components/student/updatePassword.vue'
import resume from '../components/student/resumecenter.vue'
import position from '@/components/student/position.vue'
import emailBox from '../components/student/emailbox.vue'

import system from '../views/admin/admin.vue'
// import PersonInfomatoinDisplay from '@/components/boss/bossSpace/personInfomatoinDisplay.vue';
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    // //路由重构，暂时不用理会
    // {
    //   path:'/student',
    //   name:'student',
    //   component:()=>import('../views/student/student.vue'),
    //   children:[
    //     {
    //       path: 'report',
    //       name: 'report',
    //       component: report,//素质报告
    //     },{
    //       path:'/certificateAuthority',//认证中心
    //       name:'certificateAuthority',
    //       redirect:'/certificateAuthority/competition',
    //       component:certificateAuthority,
    //       children: [ { path: 'competition', component: Competition },
    //         { path: 'project-experience', component: ProjectExperience },
    //         { path: 'internship-experience', component: InternshipExperience },
    //         { path: 'activity', component: Activity },
    //         { path: 'special-group', component: SpecialGroup},
    //       ]},{
    //       path: '/assessment',//测评中心
    //       name: 'assessment',
    //       component: assessment,
    //       children:[
    //         {
    //           path:'assessmenttopic',
    //           name:assessmenttopic,
    //           component:assessmenttopic//测评题目
    //         }
    //       ]
    //     },{
    //       path:'/personalcenter',//个人中心
    //       name:personalcenter,
    //       component:personalcenter,
    //       children:[
    //         {
    //           path:'/modifiedinformation',
    //           name:modifiedinformation,
    //           component:modifiedinformation,//修改个人信息
    //         },
    //         {
    //           path:'/updatePassword',
    //           name:updatePassword,
    //           component:updatePassword,//修改密码
    //         }
    //       ]
    //     },
    //     {
    //       path:'/signIn',//签到
    //       name:'signIn',
    //       component:()=>import('../components/student/signIn.vue')
    //     },
    //   ]
    // },
    // //以上路由重构，暂时不用理会
    {
      path: '/',
      name: 'homepage',
      component: talent,
    },
    {
      path:'/position',
      name:'position',
      component:position
    },
    {
      path: '/position/emailbox',
      name: 'emailBox',
      component: emailBox,
      props: true, // 使路由参数作为 props 传递给组件
    },
    {
      path: '/report',
      name: 'report',
      component: report,

    },
    {
      path: '/register',
      name: 'register',
      component: () => import('@/components/register.vue'), // 注册页面
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/components/login.vue'), // 登录页面
    },
    {
      path: '/forgetPassword',
      name: 'forgetPassword',
      component: () => import('@/components/forgetPassword.vue'), // 找回密码页面
    },
      {
      path: '/boss',
      name: 'boss',
      meta: { name: '招聘方首页' }, 
      component: talent,
    },
    {
      path: '/boss-space',
      name: 'boss-space',
      redirect:'/boss-space/personinformation',
      meta: {name: '招聘方个人中心'},
      component: space,
      children: [ 
        // { path: 'personinformationDisplay', component:PersonInfomatoinDisplay }, 
        { path: 'personinformation', component: PersonInformation }, 
        { path: 'positionmanage', component: PositionManagement }, 
        { path: 'changepassword', component: ChangePassword }, 
        { path: 'inbox', component: Inbox }, 
        { path: 'outbox', component: Outbox},
      ]
      },

      {
      path:'/certificateAuthority',//认证中心
      name:'certificateAuthority',
      redirect:'/certificateAuthority/competition',
      component:certificateAuthority,
      children: [ { path: 'competition', component: Competition }, 
        { path: 'project-experience', component: ProjectExperience }, 
        { path: 'internship-experience', component: InternshipExperience }, 
        { path: 'activity', component: Activity }, 
        { path: 'skills', component:Skills},
        { path: 'special-group', component: SpecialGroup},
      ]},
    {
      path: '/assessment',
      name: 'assessment',
      component: assessment,
    },{
      path:'/personalcenter',
      name:personalcenter,
      component:personalcenter,
    },
    {
      path:'/modifiedinformation',
      name:modifiedinformation,
      component:modifiedinformation,
    },
    {
      path:'/assessmenttopic',
      name:assessmenttopic,
      component:assessmenttopic
    },
    {
      path:'/course',
      name:course,
      component:course,
    },
    {
      path:'/courseMessage',
      name:courseMessage,
      component:courseMessage,
    },
    {
      path:'/updatePassword',
      name:updatePassword,
      component:updatePassword,
    },{ path:'/teacher',//教师端
      name:'teacher',
      redirect:'/teacher/workBench',
      component:TeacherView,
      children: [ { path: 'workBench', component: workBench },
        { path: 'projectReview', component: ProjectReview }, 
        { path: 'competitionReview', component: CompetitionReview }, 
        { path: 'internshipReview', component: InternshipReview }, 
        { path: 'SpecialStudentManagement', component: SpecialStudentManagement }, 
        { path: 'GraduateDestinationStatistics', component: GraduateDestinationStatistics},
        { path: 'ActivityReview', component: ActivityReview},
        {path:'SpecialReview',component:SpecialReview},
        {path:'SkillsReview',component:SkillsReview}
      ]},{
      path:'/signIn',
      name:'signIn',
      component:()=>import('../components/student/signIn.vue')
    },
    {
      path: '/interestedPosition',
      name: 'interestedPosition',
      component: () => import('@/components/student/interestedPosition.vue'), // 学生选择兴趣岗位界面
    },
    {
      path: '/skillStrengths',
      name: 'skillStrengths',
      component: () => import('@/components/student/skillStrengths.vue'), // 学生选择技能特长界面
    },
    {
      path:'/resume',
      name:'resume',
      component:resume
    },{
      path:'/system',
      name: 'system',
      redirect: '/system/home',
      component:system,
      children:[
        {
          path:'home',
          name:'home',
          component:import('../components/admin/home.vue'),//用户管理页面
        },
        {
          path:'usermanage',
          name:'usermanage',
          component:import('../components/admin/usermanage.vue'),//用户管理页面
        },{
          path:'administratorManage',
          name:'administratorManage',
          component:import('../components/admin/administratorManage.vue'),//学生管理页面
        },{
          path:'studentmanage',
          name:'studentmanage',
          component:import('../components/admin/studentManage.vue'),//学生管理页面
        },{
          path:'teachermanage',
          name:'teachermanage',
          component:import('../components/admin/teacherManage.vue'),//教师管理页面
        },{
          path:'bossmanage',
          name:'bossmanage',
          component:import('../components/admin/bossManage.vue'),//招聘方管理页面
        },{
          path:'rolemanage',
          name:'rolemanage',
          component:import('../components/admin/rolemanage.vue'),//角色管理
        },{
          path:'topicmanage',
          name:'topicmanage',
          component:import('../components/admin/topicmanage.vue'),//测评题目管理
        },{
          path:'topictypemanage',
          name:'topictypemanage',
          component:import('../components/admin/topicTypeManage.vue')
        },{
          path:'noticemanage',
          name:'noticemanage',
          component:import('../components/admin/noticemanage.vue')
        },{
          path:'authmanage',
          name:'authmanage',
          component:import('../components/admin/authmanage.vue')
        },{
          path:'poststationmanage',
          name:'poststationmanage',
          component:import('../components/admin/poststationmanage.vue')
        }

      ]

    }
  ],
})


router.beforeEach((to, from, next) => {
  console.log("kkk")
  // 从Vuex store中获取isAuthenticated字段
  const prehaslogin = localStorage.getItem("prehaslogin") === "true";
  console.log(to.meta.auth)
  console.log(prehaslogin)

  
  if (to.meta.auth && !prehaslogin) {
    // 如果路由需要身份验证，并且用户尚未登录，
    // 那么重定向到登录页面
    next({ path: '/login'})
  } else {
    // 否则，允许导航
    next()
  }
})
export default router
